﻿/*************************************************************************************
 * 文 件 名:   HK_TrueFalseItem
 * 
 * 描    述:   判断题模板类
 * 
 * 版    本：  V1.0
 * 创 建 者：  京产肠饭
 * 创建时间：  2021/11/25
 * 链   接：  https://gitee.com/JingChanChangFan/hk_-unity-tools
*************************************************************************************/

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class HK_TrueFalseItem : HK_QuesItem
{
    public Toggle right_Toggle;
    public Toggle fault_Toggle;

    List<GameObject> optionBG_List = new List<GameObject>();

    List<Toggle> option_List = new List<Toggle>();

    int answerID;

    public void InitQuesItem(HK_TrueFalseData quesData, int id)
    {
        ID_Txt.text = id.ToString() + "、";

        answerID = quesData.AnswerID;

        option_List.Add(right_Toggle);
        option_List.Add(fault_Toggle);

        right_Toggle.isOn = false;
        fault_Toggle.isOn = false;

        quesName_Txt.text = quesData.QuesName;

        optionBG_List.Add(right_Toggle.transform.Find("Background").gameObject);
        optionBG_List.Add(fault_Toggle.transform.Find("Background").gameObject);

        right_Toggle.onValueChanged.AddListener(OnSelectRightToggle);
        fault_Toggle.onValueChanged.AddListener(OnSelectFaultToggle);

        analysis_Txt.text = quesData.Analysis;
    }

    void OnSelectRightToggle(bool isOn)
    {
        if (!isOn)
            return;

        isCorrect = answerID == 1 ? true : false;
    }

    void OnSelectFaultToggle(bool isOn)
    {
        if (!isOn)
            return;

        isCorrect = answerID == 0 ? true : false;
    }

    public void HideToggle()
    {
        for (int i = 0; i < optionBG_List.Count; i++)
        {
            optionBG_List[i].SetActive(false);
        }
    }

    public override bool IsDone()
    {
        isDone = false;

        for (int i = 0; i < option_List.Count; i++)
        {
            if (option_List[i].isOn)
                isDone = true;
        }

        return isDone;
    }

    public override bool IsCorrect()
    {
        return isCorrect;
    }
}
